<?php
/**
 * PhpStorm
 * User: zucheng
 * Date: 2019/3/19
 */

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Api\ApiController;
use App\Models\Member;
use App\Models\MemberAudit;
use App\Services\UmengService;
use Illuminate\Http\Request;

class DemoController extends ApiController
{
    public function test(Request $request)
    {

       try {
           $member = Member::findOrFail(62);
           $pushType = $member->role_id == Member::ROLE_DRIVER ? 'driver' : 'owner';
           $message  = '恭喜您已经通过审核';

           $paramsBuilder = [];
           switch ($member->user_platform) {
               case Member::USER_PLATFORM_ANDROID:
                   $paramsBuilder = [
                       'alias_type'  => 'user_alias',
                       'alias'       => $member->uuid,
                       "ticker"      => "审核结果通知",
                       "title"       => "审核结果通知",
                       "text"        => $message,
                       "after_open"  => "go_app",
                       "description" => "审核结果通知",
                   ];
                   break;
               case Member::USER_PLATFORM_IOS:
                   $paramsBuilder = [
                       'alert'       => [
                           'title' => '审核结果通知',
                           'body'  => $message,
                       ],  //字符串或者JSON
                       'alias_type'  => 'user_alias',
                       'alias'       => $member->uuid,
                       "description" => "审核结果通知"
                   ];
                   break;
           }

           $umengService = (new UmengService($pushType))->paramsBuilder($paramsBuilder);
           $umengService->easyCustomizedCast($member);
           echo "done\n";
       } catch (\Exception $e) {
           echo '<pre>';var_dump($e->getMessage());exit;
       }






        exit;
        return $this->json();

        try {

            $params = [
                'alert'       => [
                    'title'    => '测试标题222',
                    'subtitle' => 'subtitle',
                    'body'     => '测试body333',
                ],  //字符串或者JSON
                'alias_type'  => 'user_alias',
                'alias'       => '90cad60f-4466-3a46-a24f-8ac266edb709',
                "description" => "测试alias通知-iOS"
            ];

            // 友盟测试推送
            $umengService = new UmengService('owner');
            $result = $umengService->paramsBuilder($params)->iosCustomizedCast();
            echo '<pre>';var_dump($result);exit;

        } catch (\Exception $e) {
            echo '<pre>';var_dump($e->getMessage());exit;
        }
    }

}